<template>
    <div class="goods-list">
        <h3></h3>
        <div class="good-item">
            <img src="https://img13.360buyimg.com/n1/s450x450_jfs/t19912/33/927199229/297549/8c269ff0/5b0fca0fN8d5600df.jpg" alt="">
            <h1 class="title">小米8 全面屏智能手机 6GB+64GB 黑色 全网通4G</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥2699</span>
                    <span class="old">￥2999</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩60件</span>
                </p>
            </div>
        </div>
       <router-link class="good-item" v-for="item in goodlist" :key="item.id" :to="'/home/goodsinfo/' + item.id" tag="div">
            <img :src="item.img_url"><h1>{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">{{ item.sell_price }}</span>
                    <span class="old">{{ item.market_price }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantity }}件</span>
                </p>
            </div>
        </router-link>
        <router-link class="good-item" :to="'/home/goodsinfo/1' " tag="div">
            <img src="//img13.360buyimg.com/n1/s450x450_jfs/t23269/195/1799155252/226649/5bb9d11d/5b6a8fb5N09d36b0a.png" alt="">
            <h1 class="title">魅族 16th 全面屏手机 6GB+64GB 静夜黑</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥2698</span>
                    <span class="old">￥2999</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩60件</span>
                </p>
            </div>
        </router-link>
    </div>
</template>

<script>
    export default {
       data() {
           return {
               pageindex: 1,
               goodlist: []
           }
       }, 
       created() {
           this.getGoodsList()
       },
       methods: {
           getGoodsList() {
               //获取商品列表
               this.$http.get('api/getgoods?pageindex='+ this.pageindex)
               .then(result => {
                   if(result.body.status === 0){
                       
                       this.goodlist = this.goodlist.concat(result.body.message)
                   }
               })
           }
       }
    }
</script>

<style lang="scss" scoped>
.goods-list{
    background-color: white;
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
    justify-content: space-between;
    .good-item{
        width: 49%;
        border: 1px solid rgb(231, 231, 231);
        box-shadow: 0 0 9px #ccc;
        margin: 4px 0;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 290px;
        img{
            width: 100%;
        }
        .title{
            font-size: 14px;
        }
        .info{
            background-color: rgb(236, 236, 236);
            p{
                margin: 0;
                padding: 5px;
            }
            .price{
                .now{
                    color: red;
                    font-weight: bold;
                    font-size: 16px;
                }
                .old{
                    text-decoration: line-through;
                    font-size: 12px;
                    margin-left: 10px;
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;
            }
        }
    }
}
</style>
